package api

import (
	"GopherFocus/app/system/index/internal/define"
	"GopherFocus/app/system/index/internal/service"
	"GopherFocus/library/response"
	"github.com/gogf/gf/net/ghttp"
)

var Interact = interactApi{}

type interactApi struct{}

// 点赞
func (a *interactApi) Zan(r *ghttp.Request) {
	var (
		req *define.InteractZanReq
	)
	if err := r.Parse(&req); err != nil {
		response.JsonExit(r, 1, err.Error())
	}
	if err := service.Interact.Zan(r.Context(), req.Id, req.Type); err != nil {
		response.JsonExit(r, 1, err.Error())
	} else {
		response.JsonExit(r, 0, "")
	}
}

// 取消赞
func (a *interactApi) CancelZan(r *ghttp.Request) {
	var (
		req *define.InteractCancelZanReq
	)
	if err := r.Parse(&req); err != nil {
		response.JsonExit(r, 1, err.Error())
	}
	if err := service.Interact.CancelZan(r.Context(), req.Id, req.Type); err != nil {
		response.JsonExit(r, 1, err.Error())
	} else {
		response.JsonExit(r, 0, "")
	}
}

// 踩
func (a *interactApi) Cai(r *ghttp.Request) {
	var (
		req *define.InteractCaiReq
	)
	if err := r.Parse(&req); err != nil {
		response.JsonExit(r, 1, err.Error())
	}
	if err := service.Interact.Cai(r.Context(), req.Id, req.Type); err != nil {
		response.JsonExit(r, 1, err.Error())
	} else {
		response.JsonExit(r, 0, "")
	}
}

// 取消踩
func (a *interactApi) CancelCai(r *ghttp.Request) {
	var (
		req *define.InteractCancelCaiReq
	)
	if err := r.Parse(&req); err != nil {
		response.JsonExit(r, 1, err.Error())
	}
	if err := service.Interact.CancelCai(r.Context(), req.Id, req.Type); err != nil {
		response.JsonExit(r, 1, err.Error())
	} else {
		response.JsonExit(r, 0, "")
	}
}
